import React, { Component } from "react";

class Form extends Component {
  state = {
    textValue: "",
  };

  handChange = (e) => {
    this.setState({
      textValue: e.target.value,
    });
  };

  add = () => {
    // console.log(this.state.textValue);
    this.props.onAdd(this.state.textValue);
    this.setState({
      textValue: "",
    });
  };

  render() {
    return (
      <>
        <input
          type="text"
          value={this.state.textValue}
          onChange={this.handChange}
        />
        <button onClick={this.add}>添加</button>
      </>
    );
  }
}

export default Form;
